{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import random\n",
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4]\n",
      "<class 'numpy.ndarray'>\n",
      "[1 2 3 4]\n"
     ]
    }
   ],
   "source": [
    "#如何将python的列表，转为np的ndarray\n",
    "list1 = [1, 2, 3, 4]\n",
    "print(list1)\n",
    "oneArray = np.array(list1)\n",
    "print(type(oneArray))\n",
    "print(oneArray)\n",
    "#python list打印出来的元素之间有逗号\n",
    "# 而ndarray是空格"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.06753182411193848 0.013301372528076172\n"
     ]
    }
   ],
   "source": [
    "a = []\n",
    "for i in range(10000000):\n",
    "    a.append(random.random())\n",
    "t1 = time.time()\n",
    "sum1 = sum(a)\n",
    "t2 = time.time()\n",
    "\n",
    "b = np.array(a)\n",
    "t3 = time.time()\n",
    "sum2 = np.sum(b)\n",
    "t4 = time.time()\n",
    "\n",
    "print(t2 - t1, t4 - t3)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}